package cn.file.test;

import com.sun.xml.internal.stream.writers.UTF8OutputStreamWriter;

import java.io.*;
import java.net.URL;

import static java.lang.System.in;

public class StreamReaderAndWriter {
    public static void main(String args[]){
   // printTest();
        enCode();
    }
    //打印到控制台
    public static void printTest(){
       try(BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(System.out))){
           String msg="";
           while (!msg.equals("exit")){
               msg=br.readLine();
               bw.write(msg);
               bw.newLine();
               bw.flush();
           }
       }catch (IOException e){
           e.printStackTrace();
       }
    }
    //编码转换
    public static void enCode(){
        try(InputStream url=new URL("http://www.baidu.com").openStream();
            BufferedReader br=new BufferedReader(new InputStreamReader(url,"utf-8"))){
            String msg="";
            while ((msg=(br.readLine()))!=null){
                System.out.println(msg);
            }

        }catch (IOException e){
            e.printStackTrace();
        }
    }
}
